package base

//MsgOptions msg选项
type MsgOptions struct {
	ChainID       string // TODO 管理对应链名称所对应下的链,或者平行链等处理，广播以及接入时候需要判断ChainId
	TargetPeerIDs []string

	Filters   []FilterStrategy // peer节点过滤策略
	WhiteList map[string]struct{}
	BlackList map[string]struct{}
}

// MessageOption define single option function
type MessageOption func(*MsgOptions)

// WithChainID add chainId to message option
func WithChainID(chainID string) MessageOption {
	return func(o *MsgOptions) {
		o.ChainID = chainID
	}
}

// WithFilters add filter strategies to message option
func WithFilters(filter []FilterStrategy) MessageOption {
	return func(o *MsgOptions) {
		o.Filters = filter
	}
}

// WithTargetPeerIDs add target peer IDs to message option
func WithTargetPeerIDs(pid []string) MessageOption {
	return func(o *MsgOptions) {
		o.TargetPeerIDs = pid
	}
}

// GetMessageOption create MessageOptions with given options
func GetMessageOption(opts []MessageOption) *MsgOptions {
	msgOpts := &MsgOptions{}
	for _, f := range opts {
		f(msgOpts)
	}
	return msgOpts
}
